package com.sali.controller;

import com.sali.properties.AlipayProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: 测试参数注入
 * @author: sali
 * @date: 2024/7/20 16:58.
 * @version: 1.0
 */
@RestController
public class ParameterController {

    @Autowired
    private Environment environment;
    @Autowired
    private AlipayProperties alipayProperties;

    @Value("${sali.alipay.appid}")
    private String appid;
    @Value("${sali.alipay.notifyUrl}")
    private String notifyUrl;

    /**
     * Environment获取变量信息
     * @return
     */
    @GetMapping("/get/p1")
    public Map<String,Object> getParmater(){
        String appId = environment.getProperty("sali.alipay.appid");
        String notifyUrl = environment.getProperty("sali.alipay.notifyUrl");
        Map<String,Object> map = new HashMap<>();
        map.put("appid",appId);
        map.put("notifyUrl",notifyUrl);
        return map;
    }

    /**
     * Value获取变量信息
     * @return
     */
    @GetMapping("/get/p2")
    public Map<String,Object> getParmater2(){
        Map<String,Object> map = new HashMap<>();
        map.put("appid",appid);
        map.put("notifyUrl",notifyUrl);
        return map;
    }


    /**
     * alipayProperties获取变量信息
     * @return
     */
    @GetMapping("/get/p3")
    public Map<String,Object> getParmater3(){
        Map<String,Object> map = new HashMap<>();
        map.put("appid",alipayProperties.getAppid());
        map.put("notifyUrl",alipayProperties.getNotifyUrl());
        return map;
    }


    /**
     * alipayProperties数据类型处理
     * @return
     */
    @GetMapping("/get/p4")
    public AlipayProperties getParmater4(){
        return alipayProperties;
    }

}
